<template>
  <div class="h5-app-download-container h5-app-container">
    <div v-if="visible" class="wx-tip">
      <div class="item">
        微信用户请点击右上角<i class="el-icon-more" style="margin-left: 5px;" />
      </div>
      <div class="item">
        <svg-icon icon-class="iconBrower" /><span class="color-primary" style="margin-left:5px">在浏览器中打开</span>后下载
      </div>
    </div>
    <div class="top-container">
      <div class="app-info-container">
        <div class="app-logo">
          <img :src="require('@/assets/images/logo-color.png')" alt="">
        </div>
        <div class="app-title-info">
          <div class="app-title">{{ newAppVersion.name }}</div>
          <div class="app-version">
            <span style="margin-right:8px">
              平台：
              <template v-if="newAppVersion.appType==0">
                Android
              </template>
              <template v-else>
                IOS
              </template>
            </span>
            版本：{{ newAppVersion.appVersionName }}

          </div>
        </div>
      </div>
      <el-button type="primary" class="app-download" @click="downloadApp">开始下载</el-button>

    </div>
    <div class="tip-title">版本更新日志</div>
    <div class="content-container scrollbar-no-width">
      <div v-for="appVersion in appVersions" :key="appVersion.id" class="version-item">
        <div class="tip-version">版本 {{ appVersion.appVersionName }}</div>
        <ul>
          <li v-for="item in appVersion.appRemark.split('\n')" :key="item" style="line-height:25px">
            {{ item }}
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      visible: false,
      appVersions: [],
      newAppVersion: {}
    }
  },
  created() {
    this.visible = false
    this.fetchData()
  },
  methods: {
    fetchData() {
      console.log(this.$route)
      this.$store.dispatch('appVersionListByCode', this.$route.params.code).then((res) => {
        this.appVersions = res
        if (res.length > 0) {
          this.newAppVersion = res[0]
        } else {
          this.$modal.msgWarning('此编号没用对应的app记录')
        }
      })
    },
    downloadApp() {
      if (this.T.isWeiXin()) {
        this.visible = true
        return
      }
      var appType = this.newAppVersion.appType
      if (appType === 0) {
        window.location.href = this.common.getFileView(this.newAppVersion.appUrl)
      } else {
        window.location.href = this.newAppVersion.appUrl
      }
    }
  }
}
</script>
<style lang="scss" scoped>
.h5-app-download-container{
  .wx-tip{
    height: 95px;
    background: url(~@/assets/images/wx_app_download_tip.png) no-repeat 50%;
    background-size: 100%;
    position: fixed;
    right: 0;
    padding: 20px 28px;
    font-size: 14px;
    color: #02193F;
    line-height: 24px;
  }
  .top-container{
    background:-webkit-linear-gradient(top,#4a5dff,#fff);
    border-bottom: 0.5px solid #c9c9c9;
    padding: 20px;
    text-align: center;
    .app-download{
      margin: 30px auto 0;
      border-radius: 8px;
      width: 95%;
      height: 46px;
      font-size: 16px;
    }
    .app-info-container{
      margin-top: 50px;
      height: 74px;
      display: flex;
      flex-direction: row;
      .app-logo{
        height: 74px;
        width: 74px;
        background: #fff;
        text-align: center;
        padding-top: 14px;
        img{
          width: 50px;
          height: 50px;
        }
      }
      .app-title-info{
        margin-left: 15px;
        margin-top: 10px;
        text-align: left;
        .app-title{
          font-size: 20px;
          color: #142d56;
        }
        .app-version{
          font-size: 14px;
          color: #666;
        }
      }
    }
  }
  .tip-title{
    font-size: 16px;
    font-weight: bold;
    color: #02193F;
    padding: 20px 20px 0 20px;
  }
  .content-container{
    overflow: auto;
    padding: 0 25px;
    overflow: auto;
    margin: 20px 0px;
    .version-item{
      margin-bottom: 25px;
      font-size: 14px;
      color: #02193F;
    }
    .tip-version{
      font-size: 16px;
      font-weight: bold;
      color: #666;
      margin-bottom: 10px;
    }
  }
}
</style>
